<div class="container-fluid">
    <div class="block-header">
        <h2>设置 > 电子邮件 & SMS 设置</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="header">
                    <h2>电子邮件设置</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success email-settings-alert"></div>
                    <form class="email-settings" method="POST">
                        <label for="smtp_or_mail">服务器类型</label>
                        <div class="form-group">
                            <input type="radio" name="smtp_or_mail" id="smtp_or_mail-enabled" value="smtp" <?php echo ($wo['config']['smtp_or_mail'] == 'smtp') ? 'checked': '';?>>
                            <label for="smtp_or_mail-enabled">SMTP服务器</label>
                            <input type="radio" name="smtp_or_mail" id="smtp_or_mail-disabled" value="mail" <?php echo ($wo['config']['smtp_or_mail'] == 'mail') ? 'checked': '';?>>
                            <label for="smtp_or_mail-disabled" class="m-l-20">Server Mail (默认)</label>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="smtp_host" name="smtp_host" class="form-control" value="<?php echo $wo['config']['smtp_host'];?>">
                                <label class="form-label">SMTP地址</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="smtp_username" name="smtp_username" class="form-control" value="<?php echo $wo['config']['smtp_username'];?>">
                                <label class="form-label">SMTP用户名</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="password" id="smtp_password" name="smtp_password" class="form-control" value="<?php echo $wo['config']['smtp_password'];?>">
                                <label class="form-label">SMTP密码</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="smtp_port" name="smtp_port" class="form-control" value="<?php echo $wo['config']['smtp_port'];?>">
                                <label class="form-label">SMTP端口</label>
                            </div>
                        </div>
                        <label for="smtp_encryption">SMTP加密</label>
                        <div class="form-group">
                            <input type="radio" name="smtp_encryption" id="smtp_encryption-enabled" value="tls" <?php echo (strtolower($wo['config']['smtp_encryption']) == 'tls') ? 'checked': '';?>>
                            <label for="smtp_encryption-enabled">TLS</label>
                            <input type="radio" name="smtp_encryption" id="smtp_encryption-disabled" value="ssl" <?php echo (strtolower($wo['config']['smtp_encryption']) == 'ssl') ? 'checked': '';?>>
                            <label for="smtp_encryption-disabled" class="m-l-20">SSL</label>
                        </div>
                        <span class="help-block">点击“测试消息”后，测试消息将发送到您的帐户电子邮件地址.</span>
                        <span class="help-block" style="color:red;">请在测试服务器之前保存表单.</span>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">保存</button>
                        <button type="button" class="btn btn-warning m-t-15 waves-effect" onclick="Wo_TestMessage();">测试电子邮件服务器</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="header">
                    <h2>SMS设置</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success sms-settings-alert"></div>
                    <form class="sms-settings" method="POST">
                        <div class="">要开始发送短信，您必须创建一个帐户并购买积分 <a href="http://www.twilio.com">Twilio</a> <span class="red">或者</span> <a href="http://www.bulksms.com/">BulkSMS</a>.</div><br>
                        <label for="sms_provider">默认 SMS提供者</label>
                        <div class="form-group">
                            <input type="radio" name="sms_provider" id="sms_provider-enabled" value="twilio" <?php echo ($wo['config']['sms_provider'] == 'twilio') ? 'checked': '';?>>
                            <label for="sms_provider-enabled">Twilio</label>
                            <input type="radio" name="sms_provider" id="sms_provider-disabled" value="bulksms" <?php echo ($wo['config']['sms_provider'] == 'bulksms') ? 'checked': '';?>>
                            <label for="sms_provider-disabled" class="m-l-20">BulkSMS</label>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="eapi" name="eapi" class="form-control" value="<?php echo $wo['config']['eapi'];?>">
                                <label class="form-label">BulkSMS Eapi_URL</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="sms_username" name="sms_username" class="form-control" value="<?php echo $wo['config']['sms_username'];?>">
                                <label class="form-label">BulkSMS 用户名</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="password" id="sms_password" name="sms_password" class="form-control" value="<?php echo $wo['config']['sms_password'];?>">
                                <label class="form-label">BulkSMS 密码</label>
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="sms_twilio_username" name="sms_twilio_username" class="form-control" value="<?php echo $wo['config']['sms_twilio_username'];?>">
                                <label class="form-label">Twilio account_sid</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="sms_twilio_password" name="sms_twilio_password" class="form-control" value="<?php echo $wo['config']['sms_twilio_password'];?>">
                                <label class="form-label">Twilio auth_token</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="sms_t_phone_number" name="sms_t_phone_number" class="form-control" value="<?php echo $wo['config']['sms_t_phone_number'];?>">
                                <label class="form-label">Twilio 手机号码</label>
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="sms_phone_number" name="sms_phone_number" class="form-control" value="<?php echo $wo['config']['sms_phone_number'];?>">
                                <label class="form-label">你的手机号码 <small>比如 (+86..)</small></label>
                            </div>
                        </div>
                      
                        <span class="help-block">单击“测试服务器”后，测试消息将发送到您的手机</span>
                        <span class="help-block" style="color:red;">请在测试服务器之前保存表单.</span>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">保存</button>
                        <button type="button" class="btn btn-warning m-t-15 waves-effect" onclick="Wo_TestSMSMessage();">测试SMS服务器</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
function Wo_TestMessage() {
    $('form.email-settings').find('.btn-warning').text('请稍后..');
    $.get(Wo_Ajax_Requests_File(), {f:'admin_setting', s: 'test_message'}, function (data) {
        if (data.status == 200) {
            alert('发送消息!');
        } else {
            alert('错误，消息没有发送: ' + data.error);
        }
        $('form.email-settings').find('.btn-warning').text('测试电子邮件服务器');
    });
}
function Wo_TestSMSMessage() {
    $('form.sms-settings').find('.btn-warning').text('请稍后..');
    $.get(Wo_Ajax_Requests_File(), {f:'admin_setting', s: 'test_sms_message'}, function (data) {
        if (data.status == 200) {
            alert('发送消息 !');
        } else {
            alert('错误，消息没有发送: ' + data.error);
        }
        $('form.sms-settings').find('.btn-warning').text('测试SMS服务器');
    });
}
$(function() {
    var form_email_settings = $('form.email-settings');
    form_email_settings.ajaxForm({
        url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting',
        beforeSend: function() {
            form_email_settings.find('.btn-primary').text('请稍后..');
        },
        success: function(data) {
            if (data.status == 200) {
                form_email_settings.find('.btn-primary').text('保存');
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.email-settings-alert').html('<i class="fa fa-check"></i> 设置更新成功');
                setTimeout(function () {
                    $('.email-settings-alert').empty();
                }, 2000);
            }
        }
    });

    var form_sms_settings = $('form.sms-settings');
    form_sms_settings.ajaxForm({
        url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting',
        beforeSend: function() {
            form_sms_settings.find('.btn-primary').text('请稍后..');
        },
        success: function(data) {
            if (data.status == 200) {
                form_sms_settings.find('.btn-primary').text('保存');
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.sms-settings-alert').html('<i class="fa fa-check"></i> 设置更新成功');
                setTimeout(function () {
                    $('.sms-settings-alert').empty();
                }, 2000);
            }
        }
    });
});
</script>